package com.xigua.xcar.setting;

import java.util.ArrayList;

import android.app.AlertDialog;
import android.content.DialogInterface;
import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.KeyEvent;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.ListView;

import com.xigua.xcar.R;
import com.xigua.xcar.base.BaseActivity;
import com.xigua.xcar.constant.Constants;
import com.xigua.xcar.data.CommonListData;
import com.xigua.xcar.widgets.CommonList.CommonListAdapter;

public class SettingActivity extends BaseActivity {
	private static final String tag = "SettingActivity";
	private ListView mCommonList = null;
	private CommonListAdapter mCommonAdapter = null;
	private ArrayList<CommonListData> mArray = null;
	private static final int FEEDBACK = 0;
	private static final int ABOUT = 1;
	private OnClickListener mListener = new OnClickListener() {

		public void onClick(View v) {
			switch (v.getId()) {
			case FEEDBACK: {// 紧急常用
				Intent intent = new Intent(SettingActivity.this,
						FeedbackActivity.class);
				intent.putExtra(Constants.COMMON_FROMWHERE, 0);
				SettingActivity.this.startActivity(intent);
				break;
			}
			case ABOUT: {// 保险客服
				Intent intent = new Intent(SettingActivity.this,
						AboutActivity.class);
				intent.putExtra(Constants.COMMON_FROMWHERE, 1);
				SettingActivity.this.startActivity(intent);
				break;
			}
			}
		}
	};
	@Override
	protected void finalize() throws Throwable {
		// 注销的注意事项
		super.finalize();
	}

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setView(R.layout.setting);
		setTopBarTitle("设置");
		setTitleBar(0, "", 0, "");
		mArray = new ArrayList<CommonListData>();
		initData();
		mCommonList = (ListView) findViewById(R.id.listview_setting_main);
		mCommonAdapter = new CommonListAdapter(this);
		mCommonAdapter.setItemClickListener(mListener);
		mCommonAdapter.setData(mArray);
		mCommonList.setAdapter(mCommonAdapter);
	}

	private void initData() {
		CommonListData data = new CommonListData();
		data.setmShopName("建议反馈");
		data.setmResId(R.drawable.icon_rightarray);
		mArray.add(data);
		data = new CommonListData();
		data.setmShopName("关于");
		data.setmResId(R.drawable.icon_rightarray);
		mArray.add(data);
	}
	
	@Override
	protected void handleTitleBarEvent(int buttonId) {
		switch (buttonId) {
		case Constants.LEFTBUTTONID: {
			break;
		}
		case Constants.RIGHTBUTTONID: {
			break;
		}
		}
	}
	
	@Override
	public boolean onKeyDown(int keyCode, KeyEvent event) {
		Log.d(tag, "back");
		if (keyCode == KeyEvent.KEYCODE_BACK && event.getRepeatCount() == 0) { //按下的如果是BACK，同时没有重复
	    	 AlertDialog.Builder builder = new AlertDialog.Builder(this);  
	    	    builder.setTitle("提示");  
	    	    builder.setMessage("确定要退出程序吗?");  
	    	    builder.setPositiveButton("确定",  
	    	            new DialogInterface.OnClickListener() {  
	    	                public void onClick(DialogInterface dialog, int whichButton) {           
	    	                	SettingActivity.this.finish();  
	    	                }  
	    	            });  
	    	    builder.setNegativeButton("取消",  
	    	            new DialogInterface.OnClickListener() {  
	    	                public void onClick(DialogInterface dialog, int whichButton) {  
	    	                }  
	    	            }).create(); 
	    	
	    	    builder.show();
	    	    
	        return true;
	    }
		return super.onKeyDown(keyCode, event);
	}
}
